package com.huike.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.huike.dto.TallyChannelDto;
import com.huike.dto.TallyDto;
import com.huike.dto.domain.Course;
import com.huike.dto.domain.Tally;
import com.huike.pojo.BusinessOpportunity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface TallyMapper extends BaseMapper<Tally>
{
    /**
     * 客户统计-分页
     * @param tally
     * @return
     */
    List<Tally> contractStatisticsList(Tally tally);

    /**
     * 客户统计-部门查询分页
     * @return
     */
    @Select("select applicable_person,code,create_by,create_time,id,info,name,price,subject,update_by,update_time from course")
    List<Course> listSelect();

    /**
     * 部门统计-分页接口
     * @param tallyDto
     * @return
     */
    List<TallyDto> deptStatisticsList(@Param("tallyDto") TallyDto tallyDto);

    /**
     * 线索统计-分页接口
     * @param tallyDto
     * @return
     */
    List<TallyDto> cluesStatisticsList(TallyDto tallyDto);

    /**
     * 渠道统计-分页接口
     * @param tallyChannelDto
     * @return
     */
    @Select("  select a.channel,a.code,a.name,a.info,a.create_time,\n" +
            "               con.course_price * a.discount as cost,\n" +
            "               count(tbc.id) as cluesNum,\n" +
            "               SUM(CASE WHEN tbc.status = '4' THEN 1 ELSE 0 END) AS falseCluesNum,\n" +
            "               count(tbb.id) as businessNum,\n" +
            "               count(con.id) as customersNum\n" +
            "        from activity a\n" +
            "                 join tb_clue tbc on a.id = tbc.activity_id\n" +
            "                 join tb_business tbb on a.id = tbb.activity_id\n" +
            "                 join contract con on a.id = con.activity_id\n" +
            "        group by a.channel,a.code,a.name,a.info,a.create_time,\n" +
            "                 cost")
    List<TallyChannelDto> activityStatisticsList(TallyChannelDto tallyChannelDto);
}
